package com.ad.platform.api;

import cn.hutool.core.lang.Snowflake;
import com.ad.payload.model.ResultBean;
import com.ad.payload.vo.JielongTimeZoneVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/CommonApi")
public class CommonApi {


    /**
     * 获取系统当前时间
     * @return
     */
    @PostMapping("/client/noAuth/getCurrentSysTime")
    public ResultBean<String> getCurrentSysTime(){
        return ResultBean.success(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()));
    }

    /**
     * 获取雪花id
     * @return
     */
    @PostMapping("/client/noAuth/getSnowNextId")
    public JielongTimeZoneVo getSnowNextId(){
        JielongTimeZoneVo jielongTimeZoneVo = new JielongTimeZoneVo();
        Snowflake snowflake = new Snowflake(3,1);
        long l = snowflake.nextId();
        jielongTimeZoneVo.setId(l);
        jielongTimeZoneVo.setCurrentTime(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()));
        System.out.println(l);
        return jielongTimeZoneVo;
    }


}
